package com.suray.attendance.db.service.impl;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.suray.attendance.common.utils.LoggerUtil;
import com.suray.attendance.db.mapper.ProductionDataCollectDetailInfoMapper;
import com.suray.attendance.db.service.ProductionDataCollectDetailInfoDBService;
import com.suray.attendance.model.pojo.ProductionDataCollectDetailInfo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


/**
 * Description:
 * Author: linyu
 * Date: 2023/11/29
 */
@Service
public class ProductionDataCollectDetailInfoDBServiceImpl extends ServiceImpl<ProductionDataCollectDetailInfoMapper, ProductionDataCollectDetailInfo> implements ProductionDataCollectDetailInfoDBService {

    /**
     * @Description: 新增erp考勤报工的明细数据至数据库
     * @Param: []
     * @return: void
     * @Author: jly
     * @Date: 2023/11/29
     */
    @Override
    public Boolean add(ProductionDataCollectDetailInfo productionDataCollectDetailInfo) {
        try {
            if(productionDataCollectDetailInfo!=null && !StringUtils.isEmpty(productionDataCollectDetailInfo.getYida_id())){
                int insert = baseMapper.insert(productionDataCollectDetailInfo);
                return insert>0;
            }
        } catch (Exception e) {
            LoggerUtil.error("新增erp考勤报工的明细数据至production_data_collect_detail_info失败,异常信息"+e.getMessage(),ProductionDataCollectDetailInfoDBServiceImpl.class);
            e.printStackTrace();
        }
        return false;
    }

    /**
     * @param erpId
     * @Description: 防止ERP的数据重复提交至宜搭
     * @Param: [productionDataCollectDetailInfo]
     * @return: java.lang.Boolean
     * @Author: jly
     * @Date: 2023/11/30
     */
    @Override
    public ProductionDataCollectDetailInfo getProductionDataCollectDetailInfoByErpId(String erpId) {
        try {
            if(!StringUtils.isEmpty(erpId)){
                ProductionDataCollectDetailInfo productionDataCollectDetailInfo = baseMapper.selectByErpId(erpId);
                if(productionDataCollectDetailInfo!=null&&!StringUtils.isEmpty(productionDataCollectDetailInfo.getYida_id())){
                    return productionDataCollectDetailInfo;
                }else {
                    LoggerUtil.info("根据erpId="+erpId+"到production_data_collect_detail_info查询信息为空",ProductionDataCollectDetailInfoDBServiceImpl.class);
                }
            }
        } catch (Exception e) {
            LoggerUtil.error("根据erpId="+erpId+"到production_data_collect_detail_info查询信息失败,异常信息"+e.getMessage(),ProductionDataCollectDetailInfoDBServiceImpl.class);
            e.printStackTrace();
        }
        return null;
    }


}
